package com.amarsoft.apot.aspect;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 横切逻辑代码的具体实现
 * @title: BeforeOperationAspect
 * @Author szh
 * @Date: 2021/12/27 15:21
 */
@Component
@Aspect
public class BeforeOperationAspect {


    @Before("@annotation(com.amarsoft.apot.annotation.OperationAnnotation))")
    private void advice(JoinPoint joinPoint){
        // 拦截的参数值
        Object[] args = joinPoint.getArgs();
        //获取被代理的类
        Object target = joinPoint.getTarget();
        if (target.getClass().getSimpleName().equals("UserServiceImpl")) {
            if (args != null && args.length > 0) {
                Map<String, Object> paramMap = (HashMap) args[0];
                System.out.println("=========szh=="+paramMap);
                long workflowId = Long.parseLong((String) paramMap.get("workflowId"));
                Assert.isTrue(workflowId != 123, "workflowId不能为空");
            }
        }
    }

}
